<%-- 
    Document   : listtable
    Created on : Oct 28, 2011, 5:55:47 PM
    Author     : Venus
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.util.*,Beans.ThamSoHT, Beans.KhuVuc,Models.ThamSoHT_Model,Models.Ban_Model, Models.KhuVuc_Model"%>
<script type="text/javascript">
    function keypress(e){
            //Hàm dùng để ngăn người dùng nhập các ký tự khác ký tự số vào TextBox
            var keypressed = null;
            if (window.event)
            {
                keypressed = window.event.keyCode; //IE
            }
            else
            {
                keypressed = e.which; //NON-IE, Standard
            }
            if (keypressed < 48 || keypressed > 57 )
            { //CharCode của 0 là 48 (Theo bảng mã ASCII)
                //CharCode của 9 là 57 (Theo bảng mã ASCII)
                if (keypressed == 8 || keypressed == 127  )
                {//Phím Delete và Phím Back
                    return;
                }
                return false;
            }
        }
</script>
<%
            int langid = (Integer) session.getAttribute("langid"); // ngôn ngữ hiện tại
            String dsts = " 'msgservice', 'areaname', 'notice', 'rightmsg', 'order','status','tablelist','enable','disable', 'tablename', 'all', 'numberofseat' "; // chuỗi chứa các mã tham số của trang này.
            ThamSoHT[] mdsts = ThamSoHT_Model.DSThamSo(dsts, langid); // mảng chứa các tham số của trang này.

            String all = mdsts[0].getTenTS();
            String areaname = mdsts[1].getTenTS();
            String disable = mdsts[2].getTenTS();
            String enable = mdsts[3].getTenTS();
            String msgservice = mdsts[4].getTenTS();
            String notice = mdsts[5].getTenTS();
            String numberofseat = mdsts[6].getTenTS();
            String order = mdsts[7].getTenTS();
            String rightmsg = mdsts[8].getTenTS();
            String status = mdsts[9].getTenTS();
            String tablelist = mdsts[10].getTenTS();
            String tablename = mdsts[11].getTenTS();
            String msgright = notice + "/" + rightmsg;
            String servicemsg = notice + "/" + msgservice;

            Vector v = (Vector) request.getAttribute("DSBan");
            
            int numpage = 0;// khởi tạo số trang = 0
            int vsize = v.size();
            if (vsize % 6 == 0) // mỗi trang có 6 dòng
            {
                numpage = vsize / 6;
            } else {
                numpage = vsize / 6 + 1;
            }
            String xx = (String) request.getAttribute("item"); // trang hiện tại đang xem
            int item = Integer.parseInt(xx);

%>

        <div class="title">
            <%=tablelist%>
            
        </div>
        <div class="content">
            <form name="dsban" action="">
                <table class="mytable" border="0" cellpadding="0" cellspacing="0">
                    <thead>
                        <tr>
                            <th style=" width: 12%;"><%=order%></th>
                            <th style=" width: 27%;">
                                <a href="#" id="titledskv1" style="margin-top: 5px;" class="down" lang="<%=msgright %>"  name="1" onclick="BanSortTenKV( this.className, this.name, this.lang)">
                                    <div style="float:left"><%=areaname%></div>
                                    <div  id="sortkv1" class="down1"></div>
                                </a>
                            </th>
                            <th style=" width: 15%;"><%=tablename%></th>
                            <th style=" width: 15%;"><%=numberofseat %></th>
                            <th style="margin-top: 2px;">
                                <a href="#" id="titledskv2" class="down"  name="1" lang="<%=msgright %>" onclick="BanSortTTKV( this.className, this.name, this.lang)">
                                    <div><%=status%></div>
                                    <div >
                                        <div id="sortkv2" class="down2"></div>
                                        <div id="sortkv2" class="up2" style="display:none;"></div>
                                    </div>
                                </a>
                            </th>
                        </tr>
                        <tr id="searchTenKV" >
                            <th><img style=" margin-top: 2px; margin-left: 3px; margin-bottom: -7px; cursor: pointer;" alt="1" lang="<%=msgright %>" src="../images/search1.png" onclick="SearchBan(this.alt, this.lang)"></th>
                            <th >
                                <input type="textbox" style="width: 95px;" name="TENKV" class="tenkv text" size="13" alt="1" lang="<%=msgright %>"  >
                            </th>
                            <th><input type="textbox" style="width: 50px;" name="TENBAN" maxlength="3" alt="1" class="tenban text" size="5" lang="<%=msgright %>"  onkeypress="return keypress(event)"></th>
                            <th><input type="textbox" style="width: 50px;" name="SOGHE" maxlength="3" alt="1" class="soghe text" size="4" lang="<%=msgright %>"  onkeypress="return keypress(event)"></th>
                            <th>
                                <select class="select" name="TINHTRANG" id="1" lang="<%=msgright %>" onchange="SearchBan(this.id, this.lang)">
                                    <option value="all"><%= all %></option>
                                    <option value="1"><%=enable %></option>
                                    <option value="0"><%=disable %></option>
                                </select>

                            </th>
                            </tr>
                    </thead>
                    <tbody>
                        
                        <%

                                    for (int i = (item - 1) * 6; i < (item - 1) * 6 + 6 && i < vsize; i++) {
                                        Beans.Ban b = (Beans.Ban) v.elementAt(i);
                        %>
                        <tr>
                            <td class="STT"><%= i + 1%></td>
                            <td>
                            <select onchange="UpdateKVBan(this.value, this.id, this.lang)" id="<%=b.getMaBan() %>" lang="<%=msgright%>">
                                <option value="<%=b.getMaKV()%>"><%=Ban_Model.LayTenKV(b.getMaKV(), langid)%></option>
                                <%
                                    KhuVuc[] dskv = KhuVuc_Model.DSKhuVuc(b.getMaKV(), langid);
                                    for (int j = 0; j < dskv.length; j++) {%>
                                        <option value="<%=dskv[j].getMaKV() %>"><%=dskv[j].getTenKV() %></option>
                                <%  }%>
                            </select>
                        </td>
                            <td style=" padding-left: 15px;"><%=b.getTenBan() %></td>
                            <td style=" padding-left: 15px;"><%=b.getSoGhe() %></td>
                            <td>
                                <select  class="<%= b.getMaBan()%>" lang="<%=msgright%>" name="<%=b.getMaTTBan() %>" id="<%=servicemsg%>" onchange="UpdateStatusBan(this.value,  this.className, this.lang, this.name, this.id)">
                                    <%
                                                                            if (b.getTinhTrang() == 1) {%>
                                    <option value="1"><%= enable%></option>
                                    <option value="0"><%= disable%></option>
                                    <%  } else {%>
                                    <option value="0"><%= disable%></option>
                                    <option value="1"><%= enable%></option>
                                    <%  }
                                    %>
                                </select>
                            </td>
                        </tr>
                        <%  }
                        %>
                    </tbody>
                </table>
                <div class="pagination">
                    <%
                                int trang = 1;
                                if (item > 1) {
                                    trang = item - 1;
                                }
                    %>
                    <%
                                if (vsize > 10) {%>
                    <a href="#" class="prev" lang="<%=msgright%>" name="<%= trang%>" onclick="NewTable(this.name, this.lang)">«</a>
                    <%
                                                        for (int c = 1; c <= numpage; c++) {
                                                            if (numpage < 10) {
                                                                if (c != item) {%>
                    <a href="#" lang="<%=msgright%>"  name="<%= c%>" onclick="NewTable(this.name, this.lang)" ><%= c%></a>
                    <%                } else {%>
                    <a class="current"> <%= c%></a>
                    <%                }
                                                      } else {
                                                          if (c == item && item == 1) {%>
                    <a href="#" lang="<%=msgright%>" class="current"   name="<%= item%>" onclick="NewTable(this.name, this.lang)"><%= item%></a>
                    <a href="#" lang="<%=msgright%>"   name="<%= item + 1%>" onclick="NewTable(this.name, this.lang)"><%= item + 1%></a>
                    <a href="#" lang="<%=msgright%>"   name="<%= item + 2%>" onclick="NewTable(this.name, this.lang)"><%= item + 2%></a>
                    <a href="#" lang="<%=msgright%>"   name="<%= item + 3%>" onclick="NewTable(this.name, this.lang)"><%= item + 3%></a>
                    ...
                    <a href="#" lang="<%=msgright%>"   name="<%= numpage - 3%>" onclick="NewTable(this.name, this.lang)"><%= numpage - 3%></a>
                    <a href="#" lang="<%=msgright%>"   name="<%= numpage - 2%>" onclick="NewTable(this.name, this.lang)"><%= numpage - 2%></a>
                    <a href="#" lang="<%=msgright%>"   name="<%= numpage - 1%>" onclick="NewTable(this.name, this.lang)"><%= numpage - 1%></a>
                    <a href="#" lang="<%=msgright%>"   name="<%= numpage%>" onclick="NewTable(this.name, this.lang)"><%= numpage%></a>
                    <%            }
                                                          if (c == item && item != 1) {
                                                              if (item < (numpage / 2)) {%>

                    <a href="#" lang="<%=msgright%>"   name="<%= item - 1%>" onclick="NewTable(this.name, this.lang)"><%= item - 1%></a>
                    <a href="#" lang="<%=msgright%>" class="current"  name="<%= item%>" onclick="NewTable(this.name, this.lang)"><%= item%></a>
                    <a href="#" lang="<%=msgright%>"   name="<%= item + 1%>" onclick="NewTable(this.name, this.lang)"><%= item + 1%></a>
                    <a href="#" lang="<%=msgright%>"   name="<%= item + 2%>" onclick="NewTable(this.name, this.lang)"><%= item + 2%></a>

                    ...
                    <a href="#" lang="<%=msgright%>"   name="<%= numpage - 3%>" onclick="NewTable(this.name, this.lang)"><%= numpage - 3%></a>
                    <a href="#" lang="<%=msgright%>"   name="<%= numpage - 2%>" onclick="NewTable(this.name, this.lang)"><%= numpage - 2%></a>
                    <a href="#" lang="<%=msgright%>"   name="<%= numpage - 1%>" onclick="NewTable(this.name, this.lang)"><%= numpage - 1%></a>
                    <a href="#" lang="<%=msgright%>"   name="<%= numpage%>" onclick="NewTable(this.name, this.lang)"><%= numpage%></a>
                    <%                }%>
                    <%                                     if (item >= (numpage / 2) && item != numpage) {
                                                              int start = 1;
                    %>
                    <a href="#" lang="<%=msgright%>"   name="<%= start%>" onclick="NewTable(this.name, this.lang)"><%= start%></a>
                    <a href="#" lang="<%=msgright%>"   name="<%= start + 1%>" onclick="NewTable(this.name, this.lang)"><%= start + 1%></a>
                    <a href="#" lang="<%=msgright%>"   name="<%= start + 2%>" onclick="NewTable(this.name, this.lang)"><%= start + 2%></a>
                    <a href="#" lang="<%=msgright%>"   name="<%= start + 3%>" onclick="NewTable(this.name, this.lang)"><%= start + 3%></a>
                    ...
                    <a href="#" lang="<%=msgright%>"   name="<%= item - 2%>" onclick="NewTable(this.name, this.lang)"><%= item - 2%></a>
                    <a href="#" lang="<%=msgright%>"   name="<%= item - 1%>" onclick="NewTable(this.name, this.lang)"><%= item - 1%></a>
                    <a href="#" lang="<%=msgright%>" class="current"  name="<%= item%>" onclick="NewTable(this.name, this.lang)"><%= item%></a>
                    <a href="#" lang="<%=msgright%>"   name="<%= item + 1%>" onclick="NewTable(this.name, this.lang)"><%= item + 1%></a>
                    <%                }
                    %>
                    <%                                     if (item >= (numpage / 2) && item == numpage) {
                                                              int start = 1;
                    %>
                    <a href="#" lang="<%=msgright%>"   name="<%= start%>" onclick="NewTable(this.name, this.lang)"><%= start%></a>
                    <a href="#" lang="<%=msgright%>"   name="<%= start + 1%>" onclick="NewTable(this.name, this.lang)"><%= start + 1%></a>
                    <a href="#" lang="<%=msgright%>"   name="<%= start + 2%>" onclick="NewTable(this.name, this.lang)"><%= start + 2%></a>
                    <a href="#" lang="<%=msgright%>"   name="<%= start + 3%>" onclick="NewTable(this.name, this.lang)"><%= start + 3%></a>
                    ...
                    <a href="#" lang="<%=msgright%>"   name="<%= item - 3%>" onclick="NewTable(this.name, this.lang)"><%= item - 3%></a>
                    <a href="#" lang="<%=msgright%>"   name="<%= item - 2%>" onclick="NewTable(this.name, this.lang)"><%= item - 2%></a>
                    <a href="#" lang="<%=msgright%>"   name="<%= item - 1%>" onclick="NewTable(this.name, this.lang)"><%= item - 1%></a>
                    <a href="#" lang="<%=msgright%>" class="current"  name="<%= item%>" onclick="NewTable(this.name, this.lang)"><%= item%></a>

                    <%                }
                    %>
                    <%            }
                                                            }
                                                        }
                    %>
                    <%
                                                        if (item + 1 <= numpage) {
                                                            trang = item + 1;
                                                        } else {
                                                            trang = item;
                                                        }
                    %>
                    <a href="#" lang="<%=msgright%>" class="next"  name="<%= trang%>" onclick="NewTable(this.name, this.lang)">»</a>
                    <%  }
                    %>
                </div>
            </form>
        </div>
    
